package com.hyc.DataStructure.PriorityQueue;

import java.util.Comparator;
import java.util.PriorityQueue;


public class PriorityQueueTest {
    public static void main(String[] args) {
        //PriorityQueue<String> queue = new PriorityQueue<>();
        //queue.offer("1");
        //queue.offer("2");
        //queue.offer("3");
        //queue.offer("4");
        //System.out.println(queue.poll());
        //System.out.println(queue.poll());
        //System.out.println(queue.poll());
        //System.out.println(queue.poll());

        PriorityQueue<student> studentQueue = new PriorityQueue<>(new Comparator<>() {
            @Override
            public int compare(student o1, student o2) {
                if (o1.score == o2.score) {
                    return o1.name.compareTo(o2.name);
                }
                return o1.score - o2.score;
            }

            private static final long serialVersionUID = -2730510067769567346L;
        }
        );
        studentQueue.offer(new student("atuo", 80));
        studentQueue.offer(new student("dmc", 60));
        studentQueue.offer(new student("amc", 60));
        studentQueue.offer(new student("yqing", 100));
        System.out.println(studentQueue.poll());
        System.out.println(studentQueue.poll());
        System.out.println(studentQueue.poll());
        System.out.println(studentQueue.poll());
    }


}

class student {
    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public String name;
    public int score;

    public student(String name, int score) {
        this.name = name;
        this.score = score;
    }
}